package org.extremecomponents.table.view.freemarker.extend;

import org.apache.commons.lang.StringUtils;
import org.extremecomponents.table.bean.Column;
import org.extremecomponents.table.cell.Cell;
import org.extremecomponents.table.core.TableModel;
import org.extremecomponents.table.core.TableModelUtils;

/**
 * @author Eccn-sshwsfc
 *
 */
public class ColumnExtend {

	protected TableModel model;
	protected Column column;

	public ColumnExtend(TableModel model, Column column) {
		this.model = model;
		this.column = column;
	}
	
	public String getFilterCellDisplay(){
		boolean cleared = model.getLimit().isCleared();
		String value = model.getLimit().getFilterSet().getFilterValue(column.getAlias());
        if (cleared || StringUtils.isEmpty(value)) {
            value = "";
        }
        Cell cell = TableModelUtils.getFilterCell(column, value);
        return cell.getHtmlDisplay(model, column);
	}
	
	public String getHeaderCellDisplay(){
		Cell cell = TableModelUtils.getHeaderCell(column, column.getTitle());

        boolean isExported = model.getLimit().isExported();
        if (!isExported) {
            return cell.getHtmlDisplay(model, column);
        } else {
            return cell.getExportDisplay(model, column);
        }
	}
}
